package com.hwy.struts.actions;

import org.apache.struts2.ServletActionContext;

import com.hwy.struts.domain.SysUser;
import com.hwy.struts.service.SysUserService;
import com.hwy.struts.service.impl.SysUserServiceImp;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class SysUserAction extends ActionSupport implements ModelDriven<SysUser>{
	private SysUser SysUser = new SysUser();
	public String login() throws Exception {
		SysUserService sUserService = new SysUserServiceImp();
		com.hwy.struts.domain.SysUser user = sUserService.login(SysUser);
		if(user == null) {
			this.addActionError("账户或密码错误请重新登录");
			return LOGIN;
		}else {
			// 登录 成功
			ServletActionContext.getRequest().getSession().setAttribute("admin_user", user);
			return SUCCESS;
		}
	}
	
	@Override
	public SysUser getModel() {
		
		return SysUser;
	}
	
}
